package com.br.eaccount.core.exception.mvc;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.web.servlet.ModelAndView;

import com.br.framework.exception.BaseException;
import com.br.framework.exception.mvc.MvcExceptionHandler;

@SuppressWarnings("rawtypes")
public class MvcExceptionHandlerImpl  implements FactoryBean, MvcExceptionHandler{
	private final boolean singleton = true;
	@Override
	public Object getObject() throws Exception {
		return this;
	}

	@Override
	public Class getObjectType() {
		return this.getClass();
	}

	@Override
	public boolean isSingleton() {
		return singleton;
	}

	/* (non-Javadoc)
	 * @see com.devkim.springframework.exception.mvc.DevkimMvcExceptionHandler#resolverException(java.lang.Exception)
	 */
	@Override
	public ModelAndView resolverException(Exception ex) {
		ModelAndView mav = new ModelAndView();
//		CSRF확인
		if(ex instanceof BaseException){
			String messageCode = ((BaseException) ex).getCode();
			if(messageCode.indexOf("error.csrf")>=0){
				mav.setViewName("error/csrf");
				return mav;
			}
		}
		return mav;
	}
}
